<template>
  <div class="prescription-container">
    <prescription class="prescription" :data="form" :view="true" />
  </div>
</template>

<script>
import { set } from 'js-cookie'
import prescription from '../components/prescription/index'

export default {
  name: 'PrescriptionPrint',
  components: { prescription },
  data() {
    return {
      form: {
        patient_id: 0,
        patient_name: '',
        patient_sex: '',
        patient_age: '',
        patient_id_card: '',
        patient_contact_tel: '',
        patient_addr: '',
        doctor_name: '',
        sect_name: '',
        pres_date: '2024-01-01',
        pres_id: 'NewNO',
        pres_type: '',
        charge_cat_id: '',
        amount: '217.43',
        diag_id: 101280,
        icds: [],
        list: [{
          medi_mark_id: '',
          name: '甲 孟鲁司特钠片',
          spec: '10mg*12s/鲁南贝特',
          pack: 1,
          unit_id: 4,
          unit_name: '盒',
          quantity: 10,
          resale_price: 3.8,
          amount: 38,
          medi_pass: 5,
          medi_pass_name: '口服',
          use_type_id: 3,
          use_type_name: '一天三次',
          medi_doage: 1,
          medi_unit_id: 5,
          medi_unit_name: '粒',
          medi_use: '1粒/次，口服，一天三次'
        }],
        print: true
      }
    }
  },
  mounted() {
    const pres = JSON.parse(localStorage.getItem('pres'))
    pres.print = true
    this.form = pres
    setTimeout(() => {
      this.print()      
    }, 1000)
  },
  methods: {
    async print() {
      this.$nextTick(async() => {
        await window.print()
        window.close()
        this.showHeader = true
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.prescription-container {
  display: flex;
  overflow-y: hidden;
  .prescription{
    width: 100%;
    padding: 1rem;
    margin: 0 1rem;
    overflow-y: auto;
    border : 1px solid #ccc;

  }
}
</style>
